// MotionDetcterClassDll.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "MotionDetcterClassDll.h"

CMotionDetcterClassDll::CMotionDetcterClassDll()
{
	isFirstFrame = true;
	pGrayImage = NULL;
	return;
}


CMotionDetcterClassDll::~CMotionDetcterClassDll(void)
{
	cvReleaseImage(&pGrayImage);
	ReleaseDetectModel(pDetectModel);
	return;
}

int  CMotionDetcterClassDll::FindObject(IplImage *pImage,CvRect roi)
{
	if (pImage == NULL)
	{
		return 0;
	}

	if (pImage->nChannels != 3)
	{
		return 0;
	}

	cvSetImageROI(pImage,roi);

	if (isFirstFrame == true)
	{
		pGrayImage = cvCreateImage(cvGetSize(pImage),pImage->depth,1);
		cvCvtColor(pImage,pGrayImage,CV_BGR2GRAY);
		pDetectModel = InitDetect(pGrayImage);
		isFirstFrame = false;
	}

	cvCvtColor(pImage,pGrayImage,CV_BGR2GRAY);
	FindObjects(pGrayImage,pDetectModel);

	cvResetImageROI(pImage);
	return pDetectModel->iObjCount;
}

